package com.example.sy.control;

import com.example.sy.pojo.user;
import com.example.sy.service.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class getUser {
    @Autowired
    private service services;
    @GetMapping("/getAll")
    public List<user> getAll(){
        return services.findAllStudent();
    }



     // 查找个人
    @CrossOrigin
    @GetMapping("/api/findUser")
    public Map<String,Object> findUser(@RequestParam(name = "token",required = true,defaultValue = "") String token){
     //        System.out.println(username);
     //          System.out.println( services.findone(username));
        return  services.findUser(token);
    }

    //注册个人信息
    @PostMapping("/postUser")
    public Map<String,Object> postUser(@RequestBody user user){
        int code = services.addUser(user);
        Map<String,Object> map=new HashMap<>();
    //重新new
        return new user().addResult(code);
    }

    //删除个人信息
    @PostMapping("/deleteUser")
    public Map<String,Object> deteleUser(@RequestBody user obj){
        int code = services.deleteUser(obj);
        Map<Object,String> map=new HashMap<>();
        return  new user().deleteResult(code);
    }

    //登录
    @CrossOrigin
    @PostMapping("/api/login")
    public Map<String,Object> userLogin(@RequestBody user obj){
    //        System.out.println(services.userLogin(obj));
        int size=services.userLogin(obj).size();
        Map<Object,String> map=new HashMap<>();
        return  new user().loginResult(size,obj.username,obj.password);

    }
}
